// xc_lshop/shop/gift/index/detail.js
var actbill = require('../../model/pack_index')
// var html2wxml = require('../../../html2wxml/html2wxml.js');
// var html2wxml = require('../../../../html2wxml/html2wxml.js');
var app = getApp();

Page({
  mixins: [require('../../../../xc/mixins/basicMixin')],

  /**
   * 页面的初始数据
   */
  data: {
    xcmodel:null,
    loading: true,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  xcloaddata: function (options, config) {
    // var that=this;
    this.getmodel(options.id)
  },
  afterlogin: function (options, config, userinfo) {
    if (userinfo.memberinfo) {
      this.setData({
        memberinfo: userinfo.memberinfo
      })

    }
   

  },
  getmodel(id) {
    var that=this;
    actbill.getmodel(id).then(res => {
      if(res['status']==1){
        // html2wxml.html2wxml('article', res.obj.htmlcont, that, 5);

        that.setData({
          loading:false,
          xcmodel:res['obj']
        })
      }else{
        that.error(res['message'],true)
      }
      
    })
  },
  buy(){
 
    var xcmodel=this.data.xcmodel
    if(xcmodel.num<1){
       wx.showToast({
         icon:"none",
         title: '库存不足',
       })
       return false
    }
    var model={
      activityid:0,
      activityprice:-1,
      attrnameinfo:[],
      attrs:[],
      bpid:0,
      cid:0,
      clubid: -1,
      flag: -1,
      id:xcmodel['id'],
      keyval: xcmodel['id']+"_0_0_-1_3",
      name: xcmodel['name'],
      num: 1,
      price:xcmodel['price'],
      pro_ident:-1,
      proid:xcmodel['id'],
      protype: 3,
      realprice:xcmodel['realprice'],
      simg: xcmodel['simg'],
      weight: 0,
    };

    console.log("model")
    console.log(model)

    app.globalData.temcart = {};
    app.globalData.temcart["data"] = [model];
    wx.navigateTo({
      url: '/' + app.globalData.xcsys.m + '/shop/paycore/payinfo?iscart=-1&iscard=1'
    })

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})